import { defineStore } from 'pinia'
import { ref } from 'vue'
export const useMemberStore = defineStore(
  'member',
  () => {
    const token = ref('')
    const username = ref({})
    const isLogin = ref(false)
    const userPhone = ref('')
    const userUid = ref('')
    const setToken = (value: string) => {
      token.value = value
    }
    const setusername = (value: any) => {
      username.value = value
    }
    const setIsLogin = (value: boolean) => {
      isLogin.value = value
    }
    const setUserPhone = (value: string) => {
      userPhone.value = value
    }
    const setUserUid = (value: string) => {
      userUid.value = value
    }
    return {
      token,
      username,
      setToken,
      setusername,
      isLogin,
      setIsLogin,
      userPhone,
      userUid,
      setUserPhone,
      setUserUid,
    }
  },
  // TODO: 持久化
  {
    persist: {
      storage: {
        getItem(key) {
          return uni.getStorageSync(key)
        },
        setItem(key, value) {
          uni.setStorageSync(key, value)
        },
      },
    },
  },
)
